#include "../include/DirScanner.h"

#include <dirent.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

DirScanner::DirScanner() 
{

}

DirScanner::~DirScanner() 
{

}

// void DirScanner::operator()() {

// }

vector<string> DirScanner::files() {
    return _files;
}

void DirScanner::traverse(const string& dirname) {
    DIR *dirp = opendir(dirname.c_str());
    if (dirp == nullptr) {
        perror("opendir");
        exit(0);
    }
    struct dirent *pdirent;
    while ((pdirent = readdir(dirp)) != nullptr) {
        if (!strcmp(pdirent->d_name, ".") || !strcmp(pdirent->d_name, "..")) {
            continue;
        }
        string path = dirname + "/" + pdirent->d_name;
        _files.push_back(path);
    }
}

